package com.example.demo.service.Impl;

import com.example.demo.mapper.UserMapper;
import com.example.demo.pojo.Enchanter;
import com.example.demo.pojo.LogTest;
import com.example.demo.pojo.Reincarnationlog;
import com.example.demo.service.UserService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;
    @Override
    public PageInfo rolesList(Integer page, Integer limit, LogTest logTest) {
        PageHelper.startPage(page,limit);
        List<LogTest> list = userMapper.rolesList(logTest);
        PageInfo<LogTest> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    @Override
    public void rolesStatus(LogTest logTest) {
        System.out.println(logTest);
        userMapper.rolesStatus(logTest);
    }

    @Override
    public void userreset(LogTest logTest) {
        userMapper.userreset(logTest);
    }

    @Override
    public void userAdd(LogTest logTest) {
        logTest.setPassword("123456");
        logTest.setCreate_time(LocalDateTime.now());
        logTest.setUpdate_time(LocalDateTime.now());
        logTest.setRole(4);
        logTest.setStatus(0);
        userMapper.useradd(logTest);
    }

    @Override
    public void userDelete(LogTest logTest) {
        userMapper.userdelete(logTest);
    }

    @Override
    public Enchanter userselect(Enchanter enchanters) {
        userMapper.userUpdate(enchanters);
        Enchanter userselect = userMapper.userselect(enchanters.getId());
        userselect.setGender(enchanters.getGender());
        userselect.setDescription(enchanters.getDescription());
        userselect.setCreate_time(LocalDateTime.now());
        userselect.setPhoto("管理员转勾魂者");
        return userselect;
    }

    @Override
    public void userReaper(Enchanter enchanter) {
        userMapper.userreaper(enchanter);
    }

    @Override
    public void newPassword(LogTest logTest, String username) {
        logTest.setUsername(username);
        userMapper.newPassword(logTest);
    }

    @Override
    public void newNickname(LogTest logTest, String username, String password) {
        logTest.setUsername(username);
        logTest.setPassword(password);
        System.out.println(logTest);
        userMapper.newNickname(logTest);
    }

    @Override
    public void newuserRole(LogTest logTest) {
        userMapper.newUserRole(logTest);
    }

    @Override
    public LogTest UserTokenLog(String username, String password) {
        return userMapper.UserTokenLog(username, password);
    }


}
